<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of keep</title>
  <meta name="keywords" content="keep">
  <meta name="description" content="KEEP keeps the caller workspace variables of your choice and clear the rest.">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
  <script type="text/javascript">
    if (top.frames.length == 0) { top.location = "../../index.html"; };
  </script>
</head>
<body>
<a name="_top"></a>
<!-- ../menu.html VMT_4.0_dev --><!-- menu.html utils -->
<h1>keep
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>KEEP keeps the caller workspace variables of your choice and clear the rest.</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function keep(varargin); </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment">KEEP keeps the caller workspace variables of your choice and clear the rest.
       Its usage is just like &quot;clear&quot; but only for variables.

       Xiaoning (David) Yang   xyang@lanl.gov 1998
       Revision based on comments from Michael McPartland,
       michael@gaitalf.mgh.harvard.edu, 1999</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
</ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
</ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function keep(varargin);</a>
0002 <span class="comment">%KEEP keeps the caller workspace variables of your choice and clear the rest.</span>
0003 <span class="comment">%       Its usage is just like &quot;clear&quot; but only for variables.</span>
0004 <span class="comment">%</span>
0005 <span class="comment">%       Xiaoning (David) Yang   xyang@lanl.gov 1998</span>
0006 <span class="comment">%       Revision based on comments from Michael McPartland,</span>
0007 <span class="comment">%       michael@gaitalf.mgh.harvard.edu, 1999</span>
0008  
0009 <span class="comment">%       Keep all</span>
0010 <span class="keyword">if</span> isempty(varargin)
0011         <span class="keyword">return</span>
0012 <span class="keyword">end</span>
0013 
0014 
0015 <span class="comment">%       See what are in caller workspace</span>
0016 wh = evalin(<span class="string">'caller'</span>,<span class="string">'who'</span>);
0017 
0018 
0019 <span class="comment">%       Check workspace variables</span>
0020 <span class="keyword">if</span> isempty(wh)
0021         error(<span class="string">'  There is nothing to keep!'</span>)
0022 <span class="keyword">end</span>
0023 
0024 
0025 <span class="comment">%       Construct a string containing workspace variables delimited by &quot;:&quot;</span>
0026 variable = [];
0027 <span class="keyword">for</span> i = 1:length(wh)
0028         variable = [variable,<span class="string">':'</span>,wh{i}];
0029 <span class="keyword">end</span>
0030 variable = [variable,<span class="string">':'</span>];
0031 
0032 
0033 <span class="comment">%       Extract desired variables from string</span>
0034 flag = 0;
0035 <span class="keyword">for</span> i = 1:length(varargin)
0036         I = findstr(variable,[<span class="string">':'</span>,varargin{i},<span class="string">':'</span>]);
0037         <span class="keyword">if</span> isempty(I)
0038                 disp([<span class="string">'       '</span>,varargin{i}, <span class="string">' does not exist!'</span>])
0039                 flag = 1;
0040         <span class="keyword">elseif</span> I == 1
0041                 variable = variable(1+length(varargin{i})+1:length(variable));
0042         <span class="keyword">elseif</span> I+length(varargin{i})+1 == length(variable)
0043                 variable = variable(1:I);
0044         <span class="keyword">else</span>
0045                 variable = [variable(1:I),variable(I+length(varargin{i})+2:length(variable))];
0046         <span class="keyword">end</span>
0047 <span class="keyword">end</span>
0048 
0049 
0050 <span class="comment">%       No delete if some input variables do not exist</span>
0051 <span class="keyword">if</span> flag == 1
0052         disp(<span class="string">'       No variables are deleted!'</span>)
0053         <span class="keyword">return</span>
0054 <span class="keyword">end</span>
0055 
0056 
0057 <span class="comment">%       Convert string back to cell and delete the rest</span>
0058 I = findstr(variable,<span class="string">':'</span>);
0059 <span class="keyword">if</span> length(I) ~= 1
0060         <span class="keyword">for</span> i = 1:length(I)-1
0061                 <span class="keyword">if</span> i ~= length(I)-1
0062                         del(i) = {[variable(I(i)+1:I(i+1)-1),<span class="string">' '</span>]};
0063                 <span class="keyword">else</span>
0064                         del(i) = {variable(I(i)+1:length(variable)-1)};
0065                 <span class="keyword">end</span>
0066         <span class="keyword">end</span>
0067         evalin(<span class="string">'caller'</span>,[<span class="string">'clear '</span>,del{:}])
0068 <span class="keyword">end</span></pre></div>
<hr><address>Generated on Thu 21-Mar-2013 09:32:01 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2005</address>
</body>
</html>